package muilty_thread.pic_java_design_pattern.SingleThreadedExecution;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/09/09 19:13
 */


public class Gate {
    private int counter=0;
    private String name = "NoBody";
    private String address = "NoWhere";

    public synchronized void pass(String name, String address) {
        this.counter++;
        this.name = name;
        this.address = address;
        check();
    }

    @Override
    public synchronized String toString() {
        return "Gate{" +
                "counter=" + counter +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                '}';
    }

    private void check(){
        if (name.charAt(0) != address.charAt(0)) {
            System.out.println("=====================BROKEN!++++++++++++"+toString());
        }
    }
}
